#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/12/27 20:21
# @Author  : Sun
# @File    : modify_family_note.py
# @Software: PyCharm
import json

import requests

from common.read_yaml import ReadYaml
from common.write_log import WriteLog


class ModifyPartyMemberInfo:
    _URL = ReadYaml().read_yaml().get('domain') + \
        "/relation/sns/modifyPartyMemberInfo"
    _DATA = {
        "partyId": 20000711,
        "duties": None,
        "modifiedMemberJJUid": None
    }
    _DATASET = {
        "partyId": 20000711,
        "duties": None,
        "modifiedMemberJJUid": None
    }
    _DATACANCEL = {
        "partyId": 20000711,
        "duties": None,
        "modifiedMemberJJUid": None
    }
    _HEADERS = {
        'platform': 'RN',
        'Authorization': None,
        'Content-Type': 'application/json;charset=utf-8'
    }
    _HEADERSSET = {
        'platform': 'RN',
        'Authorization': None,
        'Content-Type': 'application/json;charset=utf-8'
    }
    _HEADERSCANCEL = {
        'platform': 'RN',
        'Authorization': None,
        'Content-Type': 'application/json;charset=utf-8'
    }

    # JJUid为族长UID
    # modifiedMemberJJUid为成员UID
    # duties为1为设置管理员，0为移除管理员
    def modify_party_member_info(
            self, JJUid, duties=None, modifiedMemberJJUid=None):
        # self._HEADERS['Authorization'] = GetFamilyToken(
        # ).get_token(JJUid=JJUid)
        self._HEADERS['authorization'] = ReadYaml().read_yaml(file_path="./config/family_token.yaml").get(JJUid)
        self._DATA['duties'] = duties
        self._DATA['modifiedMemberJJUid'] = modifiedMemberJJUid
        r = requests.request(
            method='POST',
            url=self._URL,
            headers=self._HEADERS,
            data=json.dumps(self._DATA))
        result = json.dumps(r.json(), ensure_ascii=False, indent=4)
        WriteLog().write_log().info(result)
        return result

    # 普通用户设置管理员
    def set_administrator_normal(
            self, JJUid, duties=None, modifiedMemberJJUid=None):
        # 先取消管理员权限
        self.modify_party_member_info(JJUid=modifiedMemberJJUid, duties=0, modifiedMemberJJUid=JJUid)
        self._HEADERSSET['authorization'] = ReadYaml().read_yaml(file_path="./config/family_token.yaml").get(JJUid)
        self._DATASET['duties'] = duties
        self._DATASET['modifiedMemberJJUid'] = modifiedMemberJJUid
        r = requests.request(
            method='POST',
            url=self._URL,
            headers=self._HEADERSSET,
            data=json.dumps(self._DATASET))
        result = json.dumps(r.json(), ensure_ascii=False, indent=4)
        WriteLog().write_log().info(result)
        return result

    # 普通用户设置管理员
    def cancel_administrator_normal(
            self, JJUid, duties=None, modifiedMemberJJUid=None):
        # 先取消管理员权限
        self.modify_party_member_info(JJUid=modifiedMemberJJUid, duties=0, modifiedMemberJJUid=JJUid)
        self._HEADERSCANCEL['authorization'] = ReadYaml().read_yaml(file_path="./config/family_token.yaml").get(JJUid)
        self._DATACANCEL['duties'] = duties
        self._DATACANCEL['modifiedMemberJJUid'] = modifiedMemberJJUid
        r = requests.request(
            method='POST',
            url=self._URL,
            headers=self._HEADERSSET,
            data=json.dumps(self._DATASET))
        result = json.dumps(r.json(), ensure_ascii=False, indent=4)
        WriteLog().write_log().info(result)
        return result


if __name__ == '__main__':
    ModifyPartyMemberInfo().modify_party_member_info(JJUid=106146203)
